<?php 
/**
 * @author Shuanghe 2015-6-30 下午02:56:20
 */
    class Services_Tbsb extends Services_TaobaoClient {
		public $tbQuery;
		public $tbClient;
		
		/**
         * 构造方法
         */
		public function __construct(){
		$this->tbQuery = new Services_TaobaoQuery();
		$this->tbClient = new Services_TaobaoClient();
        }
		
		/**
         * 设置方法名
		 * @param $method
         */
		public function query($method){
			$this->tbQuery->TaobaoQuery($method);
		}
		
	   /**
		* 父类方法重写,请求执行
		* @param TaobaoQuery $query
		* @return array
		*/
		public function execute( $query){
			$apiParams = $query->getApiParams();
			$sysParams = $query->getSysParams();
			//$sysParams['partner_id'] = 'top-sdk-php-20101125';
			$sysParams['app_key'] = $query->getTopAppkey();
			$sysParams['session'] = $query->getTopSession();
			$sysParams['sign_method'] = 'md5';
			$sysParams['v'] = '2.0';
			$sysParams['timestamp'] = date('Y-m-d H:i:s');
			$sysParams['sign'] = $this->generateSign($query->getTopAppSecret(), array_merge($apiParams, $sysParams));
			$requestUrl = $query->getTopUrl() . '?';
			foreach( $sysParams as $k => $v ) {
				$requestUrl .= "$k=" . urlencode($v) . '&';
			}
			$requestUrl = substr($requestUrl, 0, - 1);
			try {
				$response = $this->curl($requestUrl, $apiParams);
			} catch ( Exception $e ) {
				print_r($e);
				return;
			}
			
			return $response;
	    }
		
		/**
         * 设置参数
		 * @param $key 
		 * @param $val
         */
		public function set($key,$val){
			$this->tbQuery->setParam($key,$val);
		}
		
		/**
         * 返回请求结果
		 * return array
         */
		public function get(){
			return json_decode($this->execute($this->tbQuery),true);
		}
		
		/**
		 * 设置Session
		 * @param $session
		 */
		 public function setSession($session){
			 $this->tbQuery->setTopSession($session);
		 }
		
	}
	
?>